import { ref } from 'vue';
import useRouter from '@/hooks/useRouter';
export default function useRegister() {
	const router = useRouter();
	// 表单数据对象
	const formData = ref({
		// phone: '17712152745', // 电话
		// code: '1', // 验证码
		// password: '123456', // 密码
		// rePassword: '123456', // 确认密码
		is_haved: 0,
		phone: '', // 电话
		code: '', // 验证码
		password: '', // 密码
		rePassword: '', // 确认密码
	} as any);
	const formRules = ref({
		phone: [{ required: true, message: '请输入手机号', trigger: 'blur' }], // 手机号校验
		password: [{ required: true, message: '请输入密码', trigger: 'blur' }], // 密码
		rePassword: [
			{
				required: true,
				message: '请输入确认密码',
				trigger: 'blur',
				validator: (value : any) => {
					if (value !== formData.value.password) {
						return Promise.reject('确认密码与密码不一致');
					}
					return Promise.resolve();
				}
			}
		], // 确认密码
		code: [{ required: true, message: '请输入验证码', trigger: 'blur' }] // 验证码
	});

	const protocol = ref(false); // 协议勾选状态
	// 协议勾选状态切换方法
	const checkboxChange = (e : { value : boolean }) => {
		protocol.value = e.value;
	};
	// 前往协议页面
	const goProtocolPage = () => { };
	// 当前步骤
	const step = ref(1);
	// 去登陆
	const goLogin = () => {
		router.redirect('/commonPage/login/login');
	};
	// 返回上一步

	return {
		protocol,
		checkboxChange,
		step,
		goLogin,
		confirm,
		formData,
		formRules,
		router,
	};
}